package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.oldplayerreturn.OldPlayerReturnUserData;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eCardType;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnModule;
import com.yanqu.road.server.gameplayer.module.player.CardModule;
import com.yanqu.road.server.manger.activity.oldplayerreturn.OldPlayerReturnMgr;

public class ReturnRoleCardRecharge extends BaseRecharge {
    public ReturnRoleCardRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        OldPlayerReturnUserData userData = OldPlayerReturnMgr.getUserData(player.getUserId());
        if (userData == null) {
            return true; //不是回归玩家不给买
        }
        int ret = player.getModule(OldPlayerReturnModule.class).checkReturnRoleIsEffective(userData);
        if (ret != 0) {
            return true; //不是回归玩家不给买
        }
        if (userData.isHadBuyCheapCard()) {
            return true;
        }
        return false;

    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        String reward = "";
        OldPlayerReturnUserData userData = OldPlayerReturnMgr.getUserData(player.getUserId());
        if (userData == null) {
            logger.error("订单: {}, 购买老玩家回归特殊特权卡商品: {} 取不到老玩家回归信息", orderNo, mallInfo.getMallId());
            return reward;
        }
        userData.setHadBuyCheapCard(true);
        player.getModule(OldPlayerReturnModule.class).syncUserFreeCardAndCheapCard();
        reward = player.getModule(CardModule.class).addCard(eCardType.MonthCard.getValue(), true, mallInfo.getMallId(), rechargeOrder);

        logger.info("订单: {}, 购买 老玩家回归专属 特权卡商品: {}", orderNo, mallInfo.getMallId());

        return reward;
    }
}
